package lesson5.example2;

import java.lang.instrument.Instrumentation;
import java.lang.instrument.UnmodifiableClassException;

public class MyAgent {

	public static void agentmain(String agentArgs, Instrumentation inst) {
		System.out.println("loading dynamic agent ...");

		MyTransformer monitor = new MyTransformer();
		inst.addTransformer(monitor,true); // 要传递true，否则不生效
		
		Class<?>[] classes = inst.getAllLoadedClasses();
		for (Class<?> c : classes) {
			if (c.getName().contains("TestDemo")) {
				try {
					inst.retransformClasses(c);
				} catch (UnmodifiableClassException e) {
					e.printStackTrace();
				}
				break;
			}
		}

		
	}
}
